// 店铺中的商品种类
// 种类名称 店铺id（外键）
module.exports = (sequelize, DataTypes) => {
  const kind = sequelize.define('kind', {
    name: DataTypes.STRING(50),
    disable: {
      type: DataTypes.BOOLEAN,
      defaultValue: false
    }
  })

  kind.associate = (models) => {
    kind.belongsTo(models.shop, {
      foreignKey: 'shopId',
      targetKey: 'shopId',
      as: 'shop'
    })
    kind.hasMany(models.good, {
      foreignKey: 'kindId',
      sourceKey: 'id',
      as: 'goods'
    })
  }
  return kind
}
